import { UserProfilesAPI } from "@/request/api"

export default {
    namespaced: true,
    state: {
        //购物车数量
        cartTotal: 0,
        //用户信息
        userInfo: {
            nickName: "游客", // 昵称
            coin: 0, // 积分
            headImg: require('@/assets/img/userImg.f8bbec5e.png') //头像
                // headImg: 'http://www.wolfcode.cn/data/upload/ueditor/20200410/5e90449b72fbc.png'
        }

    },
    getters: {},
    mutations: {
        charUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal;
            state.userInfo = payload.userInfo;
            // state.userInfo.headImg = require(state.userInfo.headImg)
        },
        initUserInfo(state) {
            state.cartTotal = 0;
            //用户信息
            state.userInfo = {
                nickName: "游客", // 昵称
                coin: 0, // 积分
                headImg: require('@/assets/img/userImg.f8bbec5e.png') //头像
            }
        }
    },
    actions: {
        async asyncCharUserInfo({ commit }) {
            let userInfoRes = await UserProfilesAPI()
            commit("charUserInfo", userInfoRes.data)
        }
    },
}